/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sales.generics.client.presenter;

import br.com.sales.generics.client.HanAbstractPresenter;
import br.com.sales.generics.client.nametoken.NameTokens;
import br.com.sales.generics.client.presenter.functions.PopUpFunctionsPresenter;
import br.com.sales.generics.client.utils.User;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.GwtEvent;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ContentSlot;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.client.proxy.RevealContentHandler;
import com.gwtplatform.mvp.client.proxy.RevealRootLayoutContentEvent;

/**
 *
 * @author v
 */
public class MyMainLayoutPresenter
        extends HanAbstractPresenter<MyMainLayoutPresenter.Display, MyMainLayoutPresenter.MyProxy>
        implements MyMainLayoutUiHandler {

    @ContentSlot
    public static final GwtEvent.Type<RevealContentHandler<?>> CONTENT_SLOT_TYPE = new GwtEvent.Type<>();
    public static boolean SCROLL_PLACE = true;
    @Inject
    private PopUpFunctionsPresenter popUpFunctionsPresenter;
        @Inject
    private User user;

    @Inject
    public MyMainLayoutPresenter(EventBus eventBus,
            MyMainLayoutPresenter.Display view,
            MyMainLayoutPresenter.MyProxy proxy) {
        super(eventBus, view, proxy);
        getView().setUiHandlers(this);
    }

    public void signOut() {
        clearSlot(CONTENT_SLOT_TYPE);
    }

    @Override
    protected void revealInParent() {
        RevealRootLayoutContentEvent.fire(this, this);
    }

    @Override
    public void onClickHistory() {
        revealPlace(NameTokens.HISTORY);
    }

    @Override
    public void onClickNewSale() {
        revealPlace(NameTokens.NEW_SALES);
    }

    @Override
    public void onCadastreMouseEvent(boolean isShow) {
        if (isShow) {
            popUpFunctionsPresenter.show();
        } else {
            popUpFunctionsPresenter.hide();
        }
    }

    @Override
    public void onLogoutClick(ClickEvent event) {
            signOut();
            user.setNmUser("");
            user.setIsManager(false);
            revealPlace(NameTokens.LOGIN);
    }

    @ProxyCodeSplit
    @NameToken(NameTokens.CONTROLLER)
    public interface MyProxy extends ProxyPlace<MyMainLayoutPresenter> {
    }

    public interface Display extends View, HasUiHandlers<MyMainLayoutUiHandler> {

    }
}
